- 建立 R 的使用環境
- 熟悉 R 語言基礎操作
- 敘述句、數列
- 查詢說明檔
- 了解 R 語言的物件的結構
- 變數型態:logical、numeric、character、factor
- 資料存放容器:list、data.frame、matrix、c()
- 特別的物件:NA、NaN、Inf
2019年7月13日
報告產出
install.packages("rmarkdown")
Document
$ equation $
$$ equation $$
在RStudio中,也可以找到RMarkdown的作弊小文件!
# Header 1
## Header 2
### Header 3
#### Header 4
##### Header 5
###### Header 6
**bold**
或 __bold__
*italics*
或 _italics_
~~想扁人~~
結果:
img: inserting images into an HTML document.
Much easier for adjusting width and height.
<img src="img/me.jpg" width="80"> #src=路徑,jpg、png皆可 <img src="img/me.jpg" height="100" width="500">
+
、*
、-
,列點文字image: 
[木下柚香](https://youtu.be/RlmeFHIwzKA?t=88)
標題一 | 標題二 -------------|------------- 123 | 456 789 | 0.0
標題一 | 標題二 |
---|---|
123 | 456 |
789 | 0.0 |
請大家以下面的文字為樣板,打出一篇簡短的自我介紹:
大家好,我是Jax(1.使用粗體)
,目前就讀於國立政治大學,興趣是:
(2.請列點)
我是男生,我長這樣: (3.請放照片)
(4.請放你的臉書連結)
想要和我做朋友的人可以加我臉書 歡迎加我好友
大家好,我是**Jax**(1.使用粗體),目前就讀於國立政治大學,興趣是:\ - 跳舞\ - 打球\ - 玩桌遊\ 我是男生,我長這樣: 想要和我做朋有的人可以加我[臉書](臉書路徑)
```{r}及 ```
包圍
```{r}
summary(cars$dist)
```
summary(cars$dist)
Min. 1st Qu. Median Mean 3rd Qu. Max. 2.00 26.00 36.00 42.98 56.00 120.00
```{r plot}
summary(cars)
plot(cars)
```
echo
(T/F): 是否顯示程式碼,output一定會呈現eval
(T/F): 是否要執行程式碼message
(T/F): 程式碼附帶訊息是否要含在outputinclude
(T/F): 程式碼及output是否要呈現,程式碼仍會執行warning
(T/F): 是否呈現warning訊息include = F
echo = F
eval = F
include = T 或照預設
defult
:show code and outputecho = FALSE
:only show outputeval = FALSE
:only show codeinclude = FALSE
: run code but don't show code & output利用每個chunk右上的設定鍵
在編輯 RMarkdown 的過程中,想要測試 chunk 中的 code 是否成功,但又不想要每次檢查都 knit,不僅花費太多不必要的時間也浪費系統資源
請大家利用 iris 的資料依照不同的品種,
畫出 Sepal.Length 及 Petal.Length 的 scatter plot
可先用R script畫出
plot(x=iris$Sepal.Length,y=iris$Petal.Length, pch=ifelse(iris$Species == 'setosa', 7, ifelse(iris$Species == 'versicolor', 8, 13)), col = ifelse(iris$Species == 'setosa', 'red', ifelse(iris$Species == 'versicolor', 'blue', 'green')),main = "Demo" , xlab = "Sepal.Length",ylab="Petal.Length")
請大家在 Rmarkdown 中產出將剛剛的 scatter plot
```{r, echo=TRUE, message=TRUE, warning=TRUE}
library(dplyr)
library(ggplot2)
```
如果不要出現額外訊息,怎麼調整?
```{r}
iris %>%
ggplot(aes(x=Sepal.Length, y=Petal.Length, color=Species)) +
geom_point(shape=1, size=2)
```
利用R Markdown 製作《一周天氣預報》書面報告。
利用R Markdown 製作《一周天氣預報》書面報告。
利用R Markdown 製作《一周天氣預報》書面報告。
dat <- read.csv("C:/Users/DELL/Desktop/NCCU/工作坊/data/weatherWin.csv") max(dat[,5]) min(dat[,4]) round(mean(dat[,5])-mean(dat[,4]),2) # 預測高溫約`r max(dat[1:2,4:5])`度,低溫約`r min(dat[1:2,4:5])`度 # 平均溫差為`r round(mean(dat[,5])-mean(dat[,4]),2)`度
預測高溫約30度,低溫約20度,平均溫差為3.86度
print(head(women))
height weight 1 58 115 2 59 117 3 60 120 4 61 123 5 62 126 6 63 129
results='asis'
knitr::kable
,呈現表格在output上```{r, results='asis'}
knitr::kable(women)
```
height | weight |
---|---|
58 | 115 |
59 | 117 |
60 | 120 |
61 | 123 |
62 | 126 |
63 | 129 |
install.packages("DT")
library(DT)
```{r}
datatable(head(iris))
```
options = list(pageLength = 數字)
參數調整# 呈現三列 datatable(iris, options = list(pageLength = 3)) # 呈現五列 datatable(cars, options = list(pageLength = 5))
datatable(iris) %>% formatStyle('Sepal.Length', color = 'red', backgroundColor = 'orange', fontWeight = 'bold')
datatable(cars) %>% formatStyle( 'dist' , target = 'row', backgroundColor = styleEqual(c(10), c('pink')) )
theme: united
表示目錄的主題選擇為 united
,可以變動--- title: "你Rmarkdown的名稱" author: "名字" date: "2019/07/13" output: html_document: theme: united toc : true toc_float: true ---
fig_width
以及fig_height: 7.5
參數調整toc_depth
表示顯示到多大的標題
toc_depth: 4
會顯示有少於或等於四個井字號 ####
的標題--- title: "你Rmarkdown的名稱" author: "名字" date: "2019/07/13" output: html_document: theme: united fig_width: 10 fig_height: 7.5 toc : true toc_depth: 4 toc_float: true ---
Output Options
…##
代表一張投影片#
主題黑幕install.packages("flexdashboard")
library(flexdashboard)
請各位同學分成5-8組,每組各做出一個R markdown報告。
報告內容為 :
每個人的
最後利用早上的demo資料(也可用R內鍵資料iris、cars等),用dplyr套件,挖掘資料,主題不限,看小組對甚麼有興趣。 最好可以用圖表達出來,如plot、hist、barplot…等
It’s possible to embed a Shiny application within a document.
Using R packages::slidify to publish your slides to the web
library(slidify) publish_github("repo", username="user_name") publish_rpubs("title","file_name.html") publish_dropbox(dir_name) publish_gist("title",file="file_name.html",publish=TRUE)
Slidify簡介 by Wush Wu
https://www.youtube.com/watch?v=P97udK2ktuY
20121203 MLDM Monday:markdown + knitr (Hangout 轉播) by Wush Wu
https://www.youtube.com/watch?v=OHKZLeKlUsM